package main;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import actions.Login;
import jline.ConsoleReader;
import ssh.SSHConfig;
import utils.Utils;

public class ClusterClient {
	String hostname;
	Thread rthread;
	Thread monthread;

	public ClusterClient() {
		try {
			SSHConfig.SSH_USER = Utils.username;
			SSHConfig.SSH_PASS = Utils.passwd;
			Login.doLogin();	
		} catch (Exception e) {
			System.err.println("Error: "+e.getMessage());
		}
	}

	public static void main(String[] args) {
		
		//TODO remove this
		if (args.length == 0) {
			Utils.username = "test";
			Utils.passwd = "test";
		}
		else
		{
			InputStreamReader converter = new InputStreamReader(System.in);
			BufferedReader in = new BufferedReader(converter);
			System.out.print("username: ");
			try{
				Utils.username = in.readLine();
				Utils.passwd = Utils.getMd5Digest(new ConsoleReader().readLine("password for "+Utils.username+": ", new Character((char) 0)));
			}catch (Exception e) {
				System.err.println("Error: "+e.getMessage());
				System.exit(0);
			}
		}	
		new ClusterClient();
	}
}
